
package cn.edu.hit.education.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.hit.education.dao.PropertyMapper;
import cn.edu.hit.education.pojo.Property;
import cn.edu.hit.education.pojo.PropertyExample;
import cn.edu.hit.education.pojo.PropertyExample.Criteria;

@Service
public class PropertyServiceImpl implements IPropertyService {

	@Autowired
	PropertyMapper propertyMapper;

	@Override
	public int insert(Property property) {
		return propertyMapper.insert(property);
	}

	@Override
	public int deleteByPrimaryKey(int id) {
		return propertyMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int update(Property property) {
		return propertyMapper.updateByPrimaryKey(property);
	}

	@Override
	public List<Property> queryAllProperty() {
		PropertyExample example = new PropertyExample();
		PropertyExample.Criteria criteria = example.createCriteria();
		criteria.andIdGreaterThan(0);
		
		return propertyMapper.selectByExample(example);
	}

	@Override
	public List<Property> queryPropertiesByProcessId(int processId) {
		PropertyExample example = new PropertyExample();
		PropertyExample.Criteria criteria = example.createCriteria();
		criteria.andProcessIdEqualTo(processId);
		
		return propertyMapper.selectByExample(example);
	}

	@Override
	public void clearPropertyNum() {
		List<Property> properties = queryAllProperty();
		if(properties != null && properties.size() > 0){
			for (Property property : properties) {
				property.setNum(0);
				propertyMapper.updateByPrimaryKey(property);
			}
		}
	}

	
	@Override
	public Property queryPropertyById(int id) {
		return propertyMapper.selectByPrimaryKey(id);
	}

	@Override
	public Property queryPropertyByPrimaryKey(int id) {
		// TODO 自动生成的方法存根
		return propertyMapper.selectByPrimaryKey(id);
	}

	@Override
	public Property queryPropertyByName(String name) {
		
		return propertyMapper.queryPropertyByName(name);
	}

}
